package com.CGFrame.struts.bean.message;

import java.util.Iterator;
import java.util.List;

import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.POJOs.Sector;

public class SectorForTreeView implements TreeViewElement {
	private int Id;
	private String name;
	private int companyId;
	private int parentId;
	private int leaderId;
	
	public int getCompanyId() {
		return companyId;
	}

	public void setCompanyId(int companyId) {
		this.companyId = companyId;
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public int getLeaderId() {
		return leaderId;
	}

	public void setLeaderId(int leaderId) {
		this.leaderId = leaderId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	public boolean canExpand() {
		ProjectOperate pop=ProjectOperateFactory.getprojectOperate();
		List list=pop.Query("Sector", "parentId,"+getID(), null, null);
		if(list.isEmpty()){
			return false;
		}
		return true;
	}

	public TreeViewElement[] getChildren() {
		ProjectOperate pop=ProjectOperateFactory.getprojectOperate();
		List list=pop.Query("Sector", "parentId,"+getID(), null, null);
		if(list.isEmpty()){
			return null;
		}
		SectorForTreeView[] tve=new SectorForTreeView[list.size()];
		Sector sector;
		int i=0;
		for(Iterator iter=list.iterator();iter.hasNext();){
			sector=(Sector)iter.next();
			tve[i]=new SectorForTreeView();
			tve[i].setId(sector.getSectorId());
			tve[i].setCompanyId(sector.getCompany().getCompanyId());
			tve[i].setLeaderId(sector.getLeaderId());
			tve[i].setName(sector.getsectorName());
			tve[i].setParentId(sector.getParentId());
			i++;
		}
		return tve;
	}

	public int getID() {
		return getId();
	}

	public String getNodeName() {
		return getName();
	}

}
